using DimensionsHelper.Common.Contracts;
using DimensionsHelper.Common.Contracts.TableFormatter.Options;

namespace DimensionsHelper.Client.ViewModels.CsvFormatter;

public partial class SigCharOptionsViewModel
    : ObservableObject, IProjectOption<SigCharOptions>
{

    [ObservableProperty]
    private bool _merge;
    

    [ObservableProperty]
    private double _gapBoundary;


    [ObservableProperty]
    private SigGapBoundaryType _gapBoundaryType;


    [ObservableProperty]
    private bool _hideSigCellChars;


    [ObservableProperty]
    private bool _hideSigColumnMarks;


    public SigCharOptionsViewModel(IServiceProvider serviceProvider)
    {
        LowerCaseStyle = serviceProvider.GetRequiredService<FontStyleOptionsViewModel>();
        UpperCaseStyle = serviceProvider.GetRequiredService<FontStyleOptionsViewModel>();
        SigMarkRowStyle = serviceProvider.GetRequiredService<RangeStyleOptionsViewModel>();
        SigResultStyle = serviceProvider.GetRequiredService<RangeStyleOptionsViewModel>();
    }


    public FontStyleOptionsViewModel LowerCaseStyle { get; }

    public FontStyleOptionsViewModel UpperCaseStyle { get; }

    public RangeStyleOptionsViewModel SigMarkRowStyle { get; }

    public RangeStyleOptionsViewModel SigResultStyle { get; }



    public SigCharOptions GetOptionObject()
    {
        return new SigCharOptions();
    }

    public bool TryWriteOption(SigCharOptions target)
    {
        target.Merge = Merge;
        target.GapBoundary = GapBoundary;
        target.GapBoundaryType = GapBoundaryType;
        target.HideSigCellCharacter = HideSigCellChars;
        target.HideSigColumnMark = HideSigColumnMarks;
        return LowerCaseStyle.TryWriteOption(target.LowerCaseStyleOptions)
            && UpperCaseStyle.TryWriteOption(target.UpperCaseStyleOptions);
    }

    public void LoadOption(SigCharOptions source)
    {
        Merge = source.Merge;
        GapBoundary = source.GapBoundary;
        GapBoundaryType = source.GapBoundaryType;
        HideSigCellChars = source.HideSigCellCharacter;
        HideSigColumnMarks = source.HideSigColumnMark;
        LowerCaseStyle.LoadOption(source.LowerCaseStyleOptions);
        UpperCaseStyle.LoadOption(source.UpperCaseStyleOptions);
    }
}